from aiogram import types
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram.types import InputFile

import client_kb
import sqlite_db
from create_bot import dp


class FSM(StatesGroup):
    doc_type_select = State()


async def create_spain(message: types.Message):
    """Клавиатура с выбором желаемого документа."""

    user_id = message.from_user.id
    await sqlite_db.sql_check_user(user_id)
    await message.answer("Выберите документ для создания", reply_markup=client_kb.kb_es)
    await FSM.doc_type_select.set()


@dp.message_handler(state=FSM.doc_type_select)
async def doc_type(message: types.Message, state: FSMContext):
    """Реагирование на выбранный документ и отправка примера заполнения с вызовом соответствующей функции."""
    from handlers.users.generate.es_country.es_id import id_client_first_name_input
    from handlers.users.generate.es_country.es_passport import (
        passport_client_first_name_input,
    )

    if message.text == "PASS 🇪🇸":
        type_doc = "PASS 🇪🇸"
        await sqlite_db.sql_add_country_user(message.from_user.id, "es_pass")
        await state.update_data(type=type_doc)
        await dp.bot.send_photo(
            chat_id=message.from_user.id,
            photo=InputFile(f"./files/es/es_passport/example.jpg"),
        )
        await passport_client_first_name_input(message, state)
    if message.text == "ID 🇪🇸":
        type_doc = "ID 🇪🇸"
        await sqlite_db.sql_add_country_user(message.from_user.id, "es_id")
        await state.update_data(type=type_doc)
        await dp.bot.send_photo(
            chat_id=message.from_user.id,
            photo=InputFile(f"./files/es/es_id/example.jpg"),
        )
        await id_client_first_name_input(message, state)
